﻿Public Class Frm_Rech_frmDossier
    Dim ref As Integer
    Public Sub remplir()
        Partager.deClt = DirectCast(Comb_nom.SelectedItem, DictionaryEntry)
        ref = Partager.deClt.Key
        List_tous.Items.Clear()
        Partager.list_recherch.Clear()
        For Each dr As Dossier In Partager.moi.List_info_fichier
            If dr.Archive = False And dr.Ref = ref Then
                Partager.list_recherch.Add(dr)
                List_tous.Items.Add(New ListViewItem(New String() {dr.Num, dr.Type_appel, dr.Tribunal}))
            End If
        Next
    End Sub
    Private Sub Frm_Rech_frmDossier_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Dossier.Enabled = True
    End Sub

    Private Sub Frm_Rech_frmDossier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
        Partager.remplirClients(Comb_nom)
    End Sub

    Private Sub Btn_Rech_mowakiilin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Rech_mowakiilin.Click
        Me.Enabled = False
        Partager.frmMoule = New Form
        Partager.frmMoule = Me
        Rech_Mowakilin.Show()
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "رقم الملف" Then
                For Each av As Dossier In Partager.moi.List_info_fichier

                    If av.Num.ToString.Contains(txt_rech.Text) And av.Archive = False And av.Ref = ref Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num, av.Type_appel, av.Tribunal}))
                    End If
                Next
            ElseIf comb_matorido_elbaht.SelectedItem = "المحكمة" Then
                For Each av As Dossier In Partager.moi.List_info_fichier


                    If av.Tribunal.ToString.Contains(txt_rech.Text) And av.Archive = False And av.Ref = ref Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num, av.Type_appel, av.Tribunal}))
                    End If
                Next
            ElseIf comb_matorido_elbaht.SelectedItem = "نوع الدعوى" Then
                For Each av As Dossier In Partager.moi.List_info_fichier

                    If av.Type_appel.ToString.Contains(txt_rech.Text) And av.Archive = False And av.Ref = ref Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num, av.Type_appel, av.Tribunal}))
                    End If

                Next
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            remplir()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click
        If List_tous.SelectedIndices.Count > 0 Then
            Dim avo As Dossier
            Dim j As Integer = -1
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch(i)
                    For Each khib As Dossier In Partager.moi.List_info_fichier
                        If khib.Archive = False Then
                            j += 1
                        End If
                        If avo.id = khib.id Then
                            Frm_Dossier.List_tous.Items(j).Focused = True
                            Frm_Dossier.List_tous.Items(j).Selected = True
                        End If
                    Next
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر ملف من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub

    Private Sub Comb_nom_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_nom.SelectedIndexChanged
        remplir()
    End Sub
End Class